package com.cloudsigns.factorymanager2.produce.bean;

import android.text.TextUtils;

import com.cloudsigns.factorymanager2.cusenum.CommonEnum;
import com.cloudsigns.factorymanager2.produce.utils.FormatTime;
import com.cloudsigns.factorymanager2.produce.utils.ParseJson;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public class WorkPartScheduleBean implements Serializable {
    //   private String strTime;// todo 冗余
    private int amount;// 日计划完成数量
    private int currentAmount;// 日计划实际完成数量
    private String id;// id
    private long scheduleDate;// 日计划的日期yyyy-MM-dd
    private CommonEnum.ScheduleDateType scheduleDateType;// 必须为以下可用值之一: [ "NORMAL", "ADJUST", "RETURN" ]   日计划日期类型：正常日计划、调整日期、返工日期
    private String status;// 日反馈状态
    private List<WorkParkAdjustOrderBean> WorkParkAdjustOrderList = new ArrayList<>();// 申请调整、报废单集合列表

    public int getAmount() {
        return amount;
    }

//    public String getAmountStr() {
//        if (amount == 0) {
//            return "";
//        }
//        return String.valueOf(amount);
//    }

    public void setAmount(int amount) {
        this.amount = amount;
    }

    public long getScheduleDate() {
        return scheduleDate;
    }

    public void setScheduleDate(long scheduleDate) {
        this.scheduleDate = scheduleDate;
    }

    public String getStrTime() {
//        if(TextUtils.isEmpty(strTime)){
        return FormatTime.getCustonFormatTime(scheduleDate, "yyyy-MM-dd");
//        }
//        return strTime;
    }

  /*  public void setStrTime(String strTime) {
        this.strTime = strTime;
    }*/

    public int getCurrentAmount() {
        return currentAmount;
    }

    public void setCurrentAmount(int currentAmount) {
        this.currentAmount = currentAmount;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public CommonEnum.ScheduleDateType getScheduleDateType() {
        return scheduleDateType;
    }

    public void setScheduleDateType(CommonEnum.ScheduleDateType scheduleDateType) {
        this.scheduleDateType = scheduleDateType;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public List<WorkParkAdjustOrderBean> getWorkParkAdjustOrderList() {
        return WorkParkAdjustOrderList;
    }

    public void setWorkParkAdjustOrderList(List<WorkParkAdjustOrderBean> workParkAdjustOrderList) {
        WorkParkAdjustOrderList = workParkAdjustOrderList;
    }

    public void parseJson(JSONObject jsonObj) throws JSONException {
        if (jsonObj.has("amount")) {
            setAmount(jsonObj.getInt("amount"));
        }
        if (jsonObj.has("currentAmount")) {
            String currentAmountStr = jsonObj.getString("currentAmount");
            if (null != currentAmountStr && !TextUtils.isEmpty(currentAmountStr) && !"null".equals(currentAmountStr)) {
                setCurrentAmount(Integer.parseInt(currentAmountStr));
            }
        }
        if (jsonObj.has("id")) {
            setId(jsonObj.getString("id"));
        }
        if (jsonObj.has("scheduleDate")) {
            String scheduleDateStr = jsonObj.getString("scheduleDate");
            if (!TextUtils.isEmpty(scheduleDateStr) && !scheduleDateStr.equals("null")) {
                setScheduleDate(Long.parseLong(scheduleDateStr));
            }
        }
        if (jsonObj.has("scheduleDateType")) {
            CommonEnum.ScheduleDateType scheduleDateType = ParseJson.parseScheduleDateType(jsonObj, "scheduleDateType");
            setScheduleDateType(scheduleDateType);
        }
        if (jsonObj.has("status")) {
            setStatus(jsonObj.getString("status"));
        }
        if (jsonObj.has("workParkAdjustOrderList")) {
            String workParkAdjustOrderListJsonArrStr = jsonObj.getString("workParkAdjustOrderList");
            if (null != workParkAdjustOrderListJsonArrStr && !workParkAdjustOrderListJsonArrStr.equals("null") && !TextUtils.isEmpty(workParkAdjustOrderListJsonArrStr)) {
                JSONArray workParkAdjustOrderListJsonArr = new JSONArray(workParkAdjustOrderListJsonArrStr);
                List<WorkParkAdjustOrderBean> workParkAdjustOrderList = new ArrayList<>();
                for (int z = 0; z < workParkAdjustOrderListJsonArr.length(); z++) {
                    WorkParkAdjustOrderBean workParkAdjustOrderBean = new WorkParkAdjustOrderBean();
                    JSONObject workParkAdjustOrderListJsonObj = (JSONObject) workParkAdjustOrderListJsonArr.get(z);
                    workParkAdjustOrderBean.parseJson(workParkAdjustOrderListJsonObj);
                    workParkAdjustOrderList.add(workParkAdjustOrderBean);
                }
            }
        }
    }
}
